//
//  MyView.m
//  Tire
//
//  Created by 王奎卿 on 2017/3/21.
//  Copyright © 2017年 wkq. All rights reserved.
//

#import "MyView.h"

@implementation MyView

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
//        self = [[NSBundle mainBundle] loadNibNamed:@"MyView" owner:nil options:nil][0];
    
    [self addSubview:self.tableView];
    [self.img addSubview:self.textBtn];
    [self.img addSubview:self.btn];
    self.tableView.tableHeaderView = _img;
    self.frame = frame;
        
    }
    return self;
    
}

- (UITableView *)tableView
{
    if (!_tableView)
    {
        _tableView = [[UITableView alloc]initWithFrame:self.frame style:UITableViewStylePlain];
        
        _tableView.delegate = self;
        
        _tableView.dataSource = self;
    }
    return _tableView;
}

- (UIButton *)btn
{
    if (!_btn)
    {
        _btn = [[UIButton alloc]initWithFrame:CGRectMake(20, 30, 100, 100)];
        
        _btn.layer.cornerRadius = 50;
        _btn.layer.masksToBounds = YES;
        _btn.backgroundColor = [UIColor redColor];
        [_btn setImage:[UIImage imageNamed:@""] forState:0];
    }
    return _btn;
}

- (UIButton *)textBtn
{
    if (!_textBtn)
    {
        _textBtn = [[UIButton alloc]initWithFrame:CGRectMake(280, 60, 100, 30)];
        
        [_textBtn setTitle:@"请登录/注册" forState:0];
        
        [_textBtn setTitleColor:[UIColor whiteColor] forState:0];
    }
    return _textBtn;
}

- (UIImageView *)img
{
    if (!_img)
    {
        _img = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, self.frame.size.width, 150)];
        
        _img.backgroundColor = [UIColor orangeColor];
    }
    return _img;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 10;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *reuseId = @"1502H";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseId];
    
    if (!cell)
    {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:reuseId];
    }
    return cell;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
